package com.itao.poi.tl;

import com.deepoove.poi.XWPFTemplate;
import com.deepoove.poi.data.PictureType;
import com.deepoove.poi.data.Pictures;
import com.deepoove.poi.util.PoitlIOUtils;
import com.itao.poi.tl.util.ResourceUtil;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.HashMap;

/**
 * 图片标签{{@lebalName}}
 *
 * @author sjt
 * @Date 2024/10/10 8:54
 */
public class ImageLebal {

    public static void main(String[] args) throws Exception {
        XWPFTemplate template = XWPFTemplate.compile(ResourceUtil.getDocxPath("image_template.docx"))
                .render(new HashMap<String, Object>() {{
                            // 指定图片路径
                            put("image", ResourceUtil.getImagePath("img.png"));
                            // svg图片
                            put("svg", "https://img.shields.io/badge/jdk-1.6%2B-orange.svg");

                            // 图片文件
                            put("image1", Pictures.ofLocal(ResourceUtil.getImagePath("img.png")).size(120, 120).create());

                            // 图片流
                            put("streamImg", Pictures.ofStream(new FileInputStream(ResourceUtil.getImagePath("img.png")), PictureType.JPEG)
                                    .size(100, 120).create());

                            // 网络图片(注意网络耗时对系统可能的性能影响)
                            put("urlImg", Pictures.ofUrl("http://deepoove.com/images/icecream.png")
                                    .size(100, 100).create());
                        }}
                );
        FileOutputStream fos = new FileOutputStream(ResourceUtil.getDocxOutPath("image_template.docx"));
        template.writeAndClose(fos);
        PoitlIOUtils.closeQuietlyMulti(template, fos);
    }
}
